Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.

Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.


Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.

Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.

Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.

Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.

Sub-head if needed

# Adjectives plot
library(stringr)
library(ggplot2)
library(grid)
library(plotly)
set.seed(122)

# Reading the dataset
data <- read.csv("./data/matrimoney.csv", header = TRUE, stringsAsFactor = FALSE)

# Function for adjectives, use case: x="ad posted by", for self = TRUE/FALSE, and match = TRUE/FALSE
find_adj <- function(x, self, match){
    person <- subset(data, Ad.by == x)
    if(self == TRUE){
       adj <- unlist(strsplit(gsub('[[:punct:]](?!\\w)', '',
                                   person$Self.description, perl=T), ' '))
       adj
    }else if(match == TRUE){
        adj <- unlist(strsplit(gsub('[[:punct:]](?!\\w)', '',
                                        person$Partner.preference,
                                    perl=T), ' '))
        adj
        
    }
    adj <- gsub("-family", "", adj)
    adj <- data.frame(table(tolower(adj)))
    adj <- adj[order(-adj$Freq),]
    adj
}


# Creating four datasets for bride/groom, using words described for self/match. Here: g stands for groom (not girl) and b for bride (not boy)
g.adj <- find_adj(x = "Boy", self = TRUE, match = FALSE)
g.match <- find_adj(x = "Boy", self = FALSE, match = TRUE)
b.adj <- find_adj(x = "Girl", self = TRUE, match = FALSE)
b.match <- find_adj(x = "Girl", self = FALSE, match = TRUE)

# Adding scatter
g.adj$dot.x <- rnorm(n=nrow(g.adj), 12, 3)
g.adj$dot.y <- rnorm(n=nrow(g.adj), 35, 3)
g.match$dot.x <- rnorm(n=nrow(g.match), 13, 4)
g.match$dot.y <- rnorm(n=nrow(g.match), 14, 3)
b.adj$dot.x <- rnorm(n=nrow(b.adj), 37, 4)
b.adj$dot.y <- rnorm(n=nrow(b.adj), 35, 4)
b.match$dot.x <- rnorm(n=nrow(b.match), 38, 4)
b.match$dot.y <- rnorm(n=nrow(b.match), 14, 5)

# Putting it all in a single dataframe
g.adj$cat <- "g.adj"
g.match$cat <- "g.match"
b.adj$cat <- "b.adj"
b.match$cat <- "b.match"
two <- rbind(g.adj, g.match, b.adj, b.match)

# Hover labels
two <- do.call(rbind, lapply(unique(two$cat), function(t){
    xyz <- subset(two, cat == t)
    top <- head(xyz, 5)
    bottom <- tail(xyz, 4)
    topbottom <- c(as.character(top$Var1),
                   as.character(bottom$Var1))
    xyz$labs <- ifelse(xyz$Var1 %in% topbottom,
                       as.character(xyz$Var1), NA)
    xyz
}))

################# Plot code ####################################

abc <- ggplot(two) + 
    geom_rect(aes(xmin = 26, xmax = 49, ymin = 2, ymax = 48),
              fill = "lightblue1") +
    geom_rect(aes(xmin = 2, xmax = 24, ymin = 2, ymax = 48),
              fill = "#F4F3AB") +
    geom_hline(yintercept=25, color = "orchid4", size=2.5) +
    geom_vline(xintercept=25, color = "orchid4", size=2.5) +
    geom_rect(aes(xmin = 23, xmax = 27, ymin = 44, ymax = 48),
              fill = "orchid4") +
    geom_rect(aes(xmin = 2, xmax = 6, ymin = 23, ymax = 27),
              fill = "tan1") +
    geom_rect(aes(xmin = 44, xmax = 48, ymin = 23, ymax = 27),
              fill = "tan1") +
    geom_rect(aes(xmin = 23, xmax = 27, ymin = 2, ymax = 6),
              fill = "orchid4") +    
   theme(
       axis.ticks.x=element_blank(), 
       axis.text.x=element_blank(),
       axis.ticks.y=element_blank(),
       axis.text.y=element_blank(),
       plot.margin=unit(c(2,1,1,1),"cm")
       ) + 
    scale_x_continuous(expand = c(0, 0), limits = c(0, 50)) +
    scale_y_continuous(expand = c(0, 2), limits = c(0, 50)) +          
    geom_point(aes(dot.x, dot.y,
                   text = Var1),
               colour = "thistle3", size = two$Freq) + 
    geom_text(aes(dot.x, dot.y, label=labs),colour="lightsalmon4",
              size=4, parse = TRUE) +
    annotate("text", x=25, y=46, label="For\nself",
             colour="white",
             size=4) +
    annotate("text", x=25, y=4, label="For\nmatch",
             colour="white",
             size=4) +
    annotate("text", x=4, y=25, label="Ad by\ngroom",
             colour="black",
             size=4) +
    annotate("text", x=46, y=25, label="Ad by\nbride",
             colour="black",
             size=4) +
    theme_void() +
    annotate("text", x = 42, y = 0,
             label = "As used in ads printed on July 19\nin a leading daily",
         size = 4,
             colour = "black") +
    annotate("text", x = 8, y = 50,
             label = "Adjectives used:",
             size = 6,
             colour = "black")   

# Minor plotly fixes
ax <- list(
    zeroline = FALSE,
    showline = FALSE,
    showticklabels = FALSE,
    showgrid = FALSE
)

p <- ggplotly(abc, tooltip = "text") %>% layout(xaxis = ax, yaxis = ax)  %>%
    layout(hoverlabel = list(bgcolor= 'indianred2'),
           font = list(
                family = "Agency FB",
                size = 30,
               color = '#ffffff')) 

p

Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.

Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.

 

Get in touch

surbhibhatia1906[at]gmail[dot]com